package org.springblade.modules.admin.task.feishu;

import cn.hutool.core.date.DateUtil;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.admin.enums.MaintainPlanContentEnum;
import org.springblade.modules.admin.service.UserPerformanceMonthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FeiShuUserPerformanceMonthJob {

	@Autowired
	private UserPerformanceMonthService userPerformanceMonthService;

	/**
	 * 定时任务：每月1日1点
	 */
	//@Scheduled(cron = "0 0 1 1 * ? ")
	@XxlJob(value = "generateFeiShuUserPerformanceMonth")
	public void generateFeiShuUserPerformanceMonth() {

		XxlJobHelper.handleSuccess("计算人员月绩效-方法(generateFeiShuUserPerformanceMonth)-[执行]开始");
		try{
			String lastMonth = DateUtil.format(DateUtil.offsetMonth(DateUtil.date(),-1),"yyyy-MM");
			userPerformanceMonthService.generateFeiShuUserPerformanceMonth(lastMonth);
			XxlJobHelper.handleSuccess("定时任务更新杨亮的计算人员月绩效数据表数据表-[执行]成功");
		}catch (Exception e){
			XxlJobHelper.handleSuccess("定时任务更新杨亮的计算人员月绩效数据表数据表-[执行]失败"+e);
		}

	}

	/**
	 * 定时任务：每月1日2点
	 */
	//@Scheduled(cron = "0 0 2 1 * ? ")
	@XxlJob(value = "generateFeiShuElevatorMaintainCostMonth")
	public void generateFeiShuElevatorMaintainCostMonth() {

		XxlJobHelper.handleSuccess("计算电梯维保成本月度-方法(generateFeiShuElevatorMaintainCostMonth)-[执行]开始");
		try{
			String lastMonth = DateUtil.format(DateUtil.offsetMonth(DateUtil.date(),-1),"yyyy-MM");
			userPerformanceMonthService.generateFeiShuElevatorMaintainCostMonth(lastMonth);
			userPerformanceMonthService.generateFeiShuElevatorPlanMonth(lastMonth);
			XxlJobHelper.handleSuccess("定时任务更新杨亮的计算电梯维保成本月度数据表数据表-[执行]成功");
		}catch (Exception e){
			XxlJobHelper.handleSuccess("定时任务更新杨亮的计算电梯维保成本月度数据表数据表-[执行]失败"+e);
		}

	}

}
